<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class notification extends CI_Controller {
	var $data;
	public function __construct()
	{
		parent::__construct();		
		$this->load->library('session');
		$this->load->model('model_user');
		$this->load->model('model_customer');
		$this->load->model('model_companies');
		$this->load->model('model_conflict');
		$data['title'] = "";
		$check = $this->session->userdata('login');
		if($check==false){
			redirect(base_url().'login/', 'refresh');
			return;
		}
	}
	
	public function index(){

		$is_account = false;
		$is_sale =false;	
		$per = $this->session->userdata('user_info');
			//print_r($per);
			$my_permisstion = $per["permission_apps"]["AM_SALE_SUPPORT"];
				if(isset($my_permisstion["user_type"])&&count($my_permisstion)>0&&$my_permisstion!=""){
					foreach($my_permisstion["user_type"] as $key => $v){
						if(strtoupper($key)=="IS_ACCOUNT"&&$v==1){							
							$is_account =true;														
						}else if(strtoupper($key)=="IS_SALE"&&$v==1){
							$is_sale =true;
						}
					}
				}

		if($is_account==true){
			$this->msgAccounter();
		}else if($is_sale==true){
	
			$this->msgLeader();
		//}else if($this->fclass->check_permission('special','is_ceo',$this->session->userdata('permissions2'),$this->session->userdata('permissions_base'))){
			//$this->msgLeader();
		}else{

		}		
	}

	public function msgLeader(){
		$array_parent_id = $this->session->userdata('parentId');
		
			$result = $this->model_conflict->selectConflictTemp(array( "uId"=>$array_parent_id,'limit'=>10,'paging'=>0));
		$cust_conflict_id = array();
		foreach($result as $val){
			$cust_conflict_id[] = $val["cust_id"];
		}
		
		$this->data["result"] 	= $this->model_conflict->selectConflict(array( "cust_conflict_id"=>$cust_conflict_id,'limit'=>10,'paging'=>0));
		
		$array=array();
		if(count($this->data["result"])>0){
			$array[]=array("result"=>0, "msg"=>"Có xung nhân viên <a href='".base_url()."conflict/'><strong> Click để xem chi tiết</strong> </a>");
		}
		echo json_encode($array);	
		
		
/*
		if(isset($_REQUEST["where"])&&$_REQUEST["where"]!=""){
			$where	=$_REQUEST["where"];
		}else{
			$where	='';
		}

		$order_by="cust_create_time ASC";

		$result = $this->model_conflict->selectConflictTemp(array("where"=>$where,"order_by"=>$order_by,"uId"=>$array_parent_id,'limit'=>10,'paging'=>$paging));
		$cust_conflict_id = array();
		foreach($result as $val){
			$cust_conflict_id[] = $val["cust_id"];
		}
		
		$this->data["result"] 	= $this->model_conflict->selectConflict(array("where"=>$where,"order_by"=>$order_by,"cust_conflict_id"=>$cust_conflict_id,'limit'=>10,'paging'=>$paging));
$array=array();
	
		foreach($this->data["result"] as $values){
			$array[]=array("result"=>0, "msg"=>"http://crm.altamedia.vn/conflict/review?id=23&type=");
		}
		*/
/*
		$array_parent_id = $this->session->userdata('parentId');
		//print_r($array_parent_id);
		$result = $this->model_conflict->selectConflict(array("uId"=>$array_parent_id));
		
		//print_r($result);
		$array=array();
		foreach($result as $values){
			$array[]=array("result"=>0, "msg"=>$values["title"]);
		}

		echo json_encode($array);	
	*/
	}

	public function msgAccounter(){
	
		$result = $this->model_companies->selectConflict(array("comp_status"=>-2));
		$array=array();
		if(count($result)>0){
			$array[]=array("result"=>0, "msg"=>"Có xung đột công ty <a href='".base_url()."conflict/'><strong> Click để xem chi tiết</strong> </a>");
		}
		echo json_encode($array);	
	
	}
}

